<template>
  <div>
    <van-list
      style="border-radius: 0; padding: 22px 16px 0;"
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <book-list
        v-for="(item, index) in books.data"
        :key="index"
        :books="item"
      />
    </van-list>
    <div>
      <back-home />
    </div>
  </div>
</template>

<script>
import BackHome from "../components/BackHome.vue";
import BookList from "../components/BookList.vue";
export default {
  components: { BookList, BackHome },
   data() {
    return {
      list: [],
      loading: false,
      finished: false,
      books:''
    };
  },
  mounted () {
     this.getBooks();
  },
  methods: {
    onLoad() {
      // 异步更新数据
      // setTimeout 仅做示例，真实场景中一般为 ajax 请求
      setTimeout(() => {
        for (let i = 0; i < 10; i++) {
          this.list.push(this.list.length + 1);
        }

        // 加载状态结束
        this.loading = false;

        // 数据全部加载完成
        if (this.list.length >= 10) {
          this.finished = true;
        }
      }, 1000);
    },
    getBooks() {
      let url = 'details'
      this.axios.get(url).then(res => {
        console.log('书:', res)
        this.axios.get(url).then(res => {
          console.log(res)
          this.books = res.data
        })
      })
    },
  },
};
</script>

<style lang="scss" scoped>
* {
  padding: 0;
  margin: 0;
}
</style>